package org.osiris.server.utils;



import java.util.Properties;

/**
 * Class to manage configuration parameters.
 * 
 * Configuration parameters must be read and provided by an external class.
 * Once provided, parameters can be retrieved with ConfigurationManager.getProperty("parameter name");
 * 
 * @author jalvaro
 */
public class ConfigurationManager
{

	protected static Properties cfg = null;
	
	/**
	 * Add all the parameters to the list of available parameters
	 * @param p	Properties with all the elements to add to the list of available parameters
	 */
	public static void addProperties(Properties p)
	{
		if(cfg==null)
		{
			cfg = new Properties();
		}
		
		cfg.putAll(p);
	}
	
	/**
	 * Get a property from the configuration file
	 * @param key	Name of the parameter to retrieve
	 * @return	The value of the property or null if property not found
	 */
	public static String getProperty(String key)
	{
		return getProperty(key, null);
	}

	/**
	 * Get a property from the configuration file
	 * @param key	Name of the parameter to retrieve
	 * @param defaultValue	Default value if parameter is not found
	 * @return	The value of the property or defaultValue if property not found
	 */
	public static String getProperty(String key, String defaultValue)
	{
		if(cfg!=null)
		{
			return cfg.getProperty(key, defaultValue);
		}
		return defaultValue;
	}
}
